$(function () {
    $("#sub").click(function () {
        let skuId = $(this).parents("ul").find(":checkbox").val();
        $.get("http://localhost:8080/Shop_war_exploded/cart/addGoodsToCart?skuId=" + skuId + "&num=-1", function () {

        })
    })

    $("#add").on("click", function () {
        let skuId = $(this).parents("ul").find(":checkbox").val();
        $.get("http://localhost:8080/Shop_war_exploded/cart/addGoodsToCart?skuId=" + skuId + "&num=1", function () {

        })
    })

    $(".delete").click(function () {
        if (confirm("确定要删除吗？")) {
            let self = $(this);
            let skuId = $(this).parents("ul").find(":checkbox").val()
            $.get("http://localhost:8080/Shop_war_exploded/cart/deleteGoodsFromCart?skuId=" + skuId, function (data) {
                if (data > 0) {
                    self.parents("ul").remove();
                    //更新购物车总数
                    $("#J_MiniCartNum").text(data);
                } else if (data == 1) {
                    alert("未登录，请登录！")
                    window.location.href("http://localhost:8080/Shop_war_exploded/users/login")
                } else {
                    alert("系统在忙，请稍候再试。。。");
                }
            })
        }
    })


})